# 省级疫情地图的绘制
import json
from pyecharts.charts import Map
from pyecharts.options import *

# 数据处理——取出河南省数据
f = open("疫情.txt", "r", encoding="UTF-8")
data_dict = f.read()
f.close()

data_dict = json.loads(data_dict)
data_dict = data_dict["areaTree"][0]["children"][3]["children"]
data_list = []
for city in data_dict:
    city_data_list = [(city["name"]+"市"),(city["total"]["confirm"])]
    if city_data_list[0] == "济源示范区市":
        city_data_list[0] = "济源市"
    data_list.append(city_data_list)


# 绘图
# 创建地图对象
map = Map()

# 添加数据
map.add("河南省确诊人数",data_list,"河南")

# 添加全局配置项
map.set_global_opts(
    title_opts=TitleOpts(title="河南省确诊人数分布图",pos_left="center",pos_bottom="1%"),
    visualmap_opts=VisualMapOpts(
        is_show=True,
        is_piecewise=True,
        pieces=[
            {"min":1,"max":9,"label":"1-9人","color":"#CCFFFF"},
            {"min":0,"max":49,"label":"100-909人","color":"#FFFF99"},
            {"min":50,"max":99,"label":"1000-4999人","color":"#FF9966"},
            {"min":100,"max":149,"label":"5000-9999人","color":"#FF6666"},
            {"min":150,"max":199,"label":"10000-99999人","color":"#CC3333"},
            {"min":200,"label":"100000-人","color":"#990033"}
        ]
    )
)

# 绘图
map.render("河南省疫情确诊人数图.html")
